package com.wc.算法基础课.C第三讲搜索与图论.bellman_ford.有边数限制的最短路;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/4/11 20:41
 * @description https://www.acwing.com/problem/content/855/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 510, M = 10010;
    static int INF = 0x3f3f3f3f;
    static int[][] edges = new int[M][3];
    static int[] dist = new int[N];
    static int[] backup = new int[N];
    static int n, m, k;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        k = sc.nextInt();
        for (int i = 1; i <= m; i++) {
            for (int j = 0; j < 3; j++) {
                edges[i][j] = sc.nextInt();
            }
        }
        int t = bellmanFord();
        if (t == INF) out.println("impossible");
        else out.println(t);
        out.flush();
    }

    static int bellmanFord() {
        Arrays.fill(dist, 1, n + 1, INF);
        dist[1] = 0;
        for (int i = 1; i <= k; i++) {
            System.arraycopy(dist, 1, backup, 1, n);
            for (int j = 1; j <= m; j++) {
                int a = edges[j][0], b = edges[j][1], w = edges[j][2];
                dist[b] = Math.min(dist[b], backup[a] + w);
            }
        }
        if (dist[n] > INF / 2) return INF;
        return dist[n];
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
